﻿#########################################################################################################
####	Author: Rahul G. Babar																		 ####
####    Purpose: Use this PowerShell script to activate the farm level feature if it is not          ####
####             already activated. Edit the script for specific requriements.						 ####
#########################################################################################################

$featureName = read-host "Enter farm level feature folder name which you want to activate"
if(($featureName -ne $null) -and ($featureName -ne ""))
{
	$farm = Get-SPFarm -ErrorAction SilentlyContinue
	if($farm -ne $null)
	{		
		$farmFeature = Get-SPFeature | Where-object {$_.DisplayName -eq $featureName}	-ErrorAction SilentlyContinue	
		if($farmFeature -ne $null)
		{
			write-host "$featureName feature is already activated at in farm" -foregroundcolor Green
			write-host
		}
		else
		{
			write-host "$featureName Feature is not activated, activating the same." -foregroundcolor Yellow
			write-host
			Enable-SPFeature -Identity $featureName -URL $farmUrl -Force
			write-host "$featureName feature activated across farm." -foregroundcolor Green
			write-host
		}			
	}
	else
	{
		write-error "Could not find local farm."
	}	
}
else
{
	write-error "Invalid feature name entered."
}